<template>
    <div>
        <table>
            <tr>
                <td>书名：</td>
                <td>价格</td>
                <td>作者</td>
            </tr>
            <tr v-for="(i,j) in booklist" :key="j">
                <td :class="{aa:j==1,bb:j==2,cc:j==0}">{{i.name}}</td>
                <td :class="{aa:j==1,bb:j==2,cc:j==0}">{{i.price}}</td>
                <td :class="{aa:j==1,bb:j==2,cc:j==0}">{{i.author_id}}</td>
            </tr>
        </table>
        <div>
            <p>
                <button @click="booksy()">首页</button>
                <button @click="booksyy()">上一页</button>
                <button v-for="(x,y) in fylist" :key="y" @click="bookdqy(p)">{{p}}</button>
                <button @click="bookxyy()">下一页</button>
                <button @click="bookwy()">尾页</button>
            </p>
        </div>
    </div>
</template>

<script>
import {RI_BOOK_show} from '../axios_send/api.js'
export default {
    name:"bkshow",
    data(){
        return{
            p:1,
            booklist:[],
            fylist:[],
            ssa:""

        }
    },
    methods:{
        booksl(){
            var data = {"page":this.p}
            RI_BOOK_show(data)
            .then(res=>{
                console.log(res);
                this.booklist = res.data
                this.fylist = res
                this.ssa = res.ssa
            })
        },
        booksy(){
            this.p = 1
            this.booksl()
        },
        booksyy(){
            if(this.p>1){
                this.p -= 1
                this.booksl()
            }else{
                this.p = 1
                this.booksl()
            }
        },
        bookdqy(){
            this.p = x
            this.booksl()
        },
        bookxyy(){
            if(this.p>=this.ssa){
                this.p = this.ssa
                this.booksl()
            }else{
                this.p += 1
                this.booksl()
            }
        },
        bookwy(){
            this.p = this.ssa
            this.booksl()
        }
    },
    created(){
        this.booksl()
    }
}
</script>

<style>
    .aa{color:red;}
    .bb{color: yellow;}
    .cc{color: lawngreen;}
</style>
